﻿<UserControl x:Class="CapstoneProjectAEReader.GUIs.LibraryGUI.LocalLibrary"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:controls="http://schemas.taloware.com.au/wpf/controls" 
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <DataTemplate x:Key="bookListTemplate">
            <DockPanel Height="64" Background="Transparent">
                <Image Source="{Binding FileType}" Height="56" Width="56" Margin="4" HorizontalAlignment="Center" />
                <StackPanel Margin="4" HorizontalAlignment="Left">
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <Label Content="Title:" FontSize="12" FontWeight="SemiBold" Foreground="LimeGreen"/>
                        <Label Content="{Binding Title}" FontSize="12" FontWeight="Medium" Foreground="LimeGreen" />
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                        <Label Content="Author:" FontSize="12" FontWeight="SemiBold" Foreground="Crimson"/>
                        <Label Content="{Binding Author}" FontSize="12" FontWeight="Medium" Foreground="Crimson"/>
                        <Label Content=" - " FontSize="12" FontWeight="SemiBold"/>
                        <Label Content="Group: " FontSize="12" FontWeight="SemiBold" Foreground="DarkOrange"/>
                        <Label Content="{Binding GroupInText}" FontSize="12" FontWeight="Medium" Foreground="Orange"/>
                    </StackPanel>
                </StackPanel>
            </DockPanel>
        </DataTemplate>
        <DataTemplate x:Key="GroupItemTemplate">
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding FileType}" Margin="8,0,0,0" Height="10" Width="10" 
                       VerticalAlignment="Center"/>
                <TextBlock Text="{Binding BookName}" FontSize="12" 
                            VerticalAlignment="Center" Margin="8,0,0,0"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="RecentReadTemplate">
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding FileType}" Height="32" Width="32"/>
                <Label Content="{Binding Title}" />
            </StackPanel>
        </DataTemplate>
        <ContextMenu x:Key="RecentReadContextMenu">
            <MenuItem x:Name="ctRecentReadOpenEbook" Click="HandleDbMouseClickTvRecentRead"/>
            <MenuItem x:Name="ctRecentReadRemoveItem" Click="HandleRemoveRecentReadItem"/>
        </ContextMenu>
        <ContextMenu x:Key="GroupContextMenu">
            <MenuItem x:Name="ctGroupUpdate" Click="HandleEditEbookGroup"/>
            <MenuItem x:Name="ctGroupDelete" Click="HandleDeleteEbookGroup"/>
        </ContextMenu>
        <ContextMenu x:Key="EbookInGroupContextMenu">
            <MenuItem x:Name="ctOpenEbook" Click="HandleOpenEbookInGroup"/>
            <MenuItem x:Name="ctRemoveEbook" Click="HandleRemoveEbookInGroup"/>
        </ContextMenu>
    </UserControl.Resources>

    <Grid x:Name="LibraryGrid" Background="CornflowerBlue">
        <controls:DialogPresenter x:Name="listBoxDialogPresenter">
            <Grid Background="CornflowerBlue" Margin="10">
                <DockPanel>
                    <Label x:Name="lbLibraryForm" Content="EBook Management" FontSize="20" Foreground="FloralWhite" DockPanel.Dock="Top"/>
                    <Grid Background="LightSkyBlue" Margin="8,8,8,2" DockPanel.Dock="Top">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal" Grid.Column="0">
                        <Label x:Name="lbSearch" VerticalAlignment="Center" Height="30"
                               FontWeight="SemiBold" HorizontalAlignment="Center" Margin="0" />
                        <TextBox HorizontalAlignment="Right" Height="24" Margin="8,2,8,2" TextWrapping="Wrap" 
                                 x:Name="txtSearch" VerticalAlignment="Center" Width="250"/>
                        <ComboBox x:Name="cbSearch" HorizontalAlignment="Center" VerticalAlignment="Center" 
                              Width="120" Height="24" Margin="10,2,10,2"/>
                        <Button x:Name="btSearch" Background="Transparent" HorizontalAlignment="Center" Margin="10,2,2,2" 
                                    VerticalAlignment="Center" BorderThickness="0" Click="HandleBtSearch">
                            <Image Source="Image/librarySearch.png" Height="20" />
                        </Button>
                    </StackPanel>
                    </Grid>

                    <Grid Margin="8,2,8,8" Height="auto" Width="auto">
                        <Grid.Background>
                            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                <GradientStop Color="AliceBlue" Offset="0" />
                                <GradientStop Color="SkyBlue" Offset="1" />
                            </LinearGradientBrush>
                        </Grid.Background>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="6"/>
                            <ColumnDefinition Width="2*"/>
                        </Grid.ColumnDefinitions>
          
                    <DockPanel Margin="5" Grid.Column="2" x:Name="BookListRoot">
                            <Border BorderBrush="SkyBlue" BorderThickness="0,0,0,2" DockPanel.Dock="Top">
                                <Label x:Name="lbBookList" FontWeight="SemiBold"/>
                            </Border>
                            <StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Right">
                                <Button x:Name="btExportBook" Background="Transparent" BorderThickness="0" Margin="4" Click="HandleBtExportBook">
                                    <Grid>
                                        <Image Source="Image/ButtonLarge.png" Height="32"/>
                                        <Label x:Name="lbExportBook" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Grid>
                                </Button>
                                <Button x:Name="btAddBook" Background="Transparent" BorderThickness="0" Margin="4" Click="HandleBtAddBook" >
                                    <Grid>
                                        <Image Source="Image/ButtonLarge.png" Height="32"/>
                                        <Label x:Name="lbAddBook" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Grid>
                                </Button>
                                <Button x:Name="btEditBook" Background="Transparent" BorderThickness="0" Margin="4" Click="HandleEditEbookDetail">
                                    <Grid>
                                        <Image Source="Image/ButtonLarge.png" Height="32"/>
                                        <Label x:Name="lbEditBook" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Grid>
                                </Button>
                                <Button x:Name="btDeleteBook" Background="Transparent" BorderThickness="0" Margin="4" Click="HandleBtDeleteEbook">
                                    <Grid>
                                        <Image Source="Image/ButtonLarge.png" Height="32"/>
                                        <Label x:Name="lbDeleteBook" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Grid>
                                </Button>
                            </StackPanel>

                            <ListView Name="listBook" ItemTemplate="{StaticResource bookListTemplate}" Margin="0,6,0,6" Background="Transparent" 
                                  BorderThickness="0" DockPanel.Dock="Top" MouseDoubleClick="HandleDoubleClick" SelectionChanged="listBook_SelectionChanged">
                                <ListView.ItemContainerStyle>
                                    <Style TargetType="ListViewItem">
                                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                                        <Setter Property="HorizontalAlignment" Value="Stretch"/>
                                    </Style>
                                </ListView.ItemContainerStyle>
                            </ListView>
                        </DockPanel>
                    <Border BorderBrush="SkyBlue" BorderThickness="2" Margin="2,8,2,8" Grid.Column="1"/>
                    <Grid Grid.Column="0" Margin="1">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <DockPanel Grid.Row="0">
                            <Border BorderBrush="SkyBlue" BorderThickness="0,0,0,2" DockPanel.Dock="Top" Margin="4">
                                <Label x:Name="lbGroup" FontWeight="SemiBold"/>
                            </Border>

                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="4" DockPanel.Dock="Bottom">
                                    <Button x:Name="btAddGroup" Background="Transparent" BorderThickness="0" Margin="4" Click="HandleAddEbookGroup">
                                        <Grid>
                                            <Image Source="Image/ButtonLarge.png" Height="24"/>
                                            <Label x:Name="lbAddGroup" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                        </Grid>
                                    </Button>
                                    <Button x:Name="btEditGroup" Background="Transparent" BorderThickness="0" Margin="4" Click="HandleEditEbookGroup">
                                    <Grid>
                                        <Image Source="Image/ButtonLarge.png" Height="24"/>
                                        <Label x:Name="lbEditGroup" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Grid>
                                </Button>
                                <Button x:Name="btDeleteGroup" Background="Transparent" BorderThickness="0" Margin="4" Click="HandleDeleteEbookGroup">
                                    <Grid>
                                        <Image Source="Image/ButtonLarge.png" Height="24"/>
                                        <Label x:Name="lbDeleteGroup" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </Grid>
                                </Button>
                            </StackPanel>
                            
                            <TreeView x:Name="GroupTreeView" Margin="4" Background="Transparent" BorderThickness="0" 
                                      DockPanel.Dock="Top" MouseDoubleClick="HandleDoubleClickGroup" 
                                      SelectedItemChanged="HandleGroupClick" ContextMenu="{StaticResource GroupContextMenu}">
                            </TreeView>
                        </DockPanel>
                        
                        <DockPanel Grid.Row="1">
                            <Border BorderBrush="SkyBlue" BorderThickness="0,0,0,2" DockPanel.Dock="Top" Margin="4">
                                <Label x:Name="lbRecentRead" FontWeight="SemiBold"/>
                            </Border>

                            <TreeView x:Name="tvRecentRead" Margin="4" Background="Transparent" BorderThickness="0" DockPanel.Dock="Top" 
                                    ItemTemplate="{StaticResource RecentReadTemplate}" MouseDoubleClick="HandleDbMouseClickTvRecentRead" ContextMenu="{StaticResource RecentReadContextMenu}">
                            </TreeView>
                        </DockPanel>
                    </Grid>
                </Grid>
            </DockPanel>
            
        </Grid>
        </controls:DialogPresenter>
    </Grid>
</UserControl>
